<?
    require_once("mvc/action/ActionForm.php");
    require_once("mvc/action/ActionMessage.php");
    require_once("mvc/action/ActionMessages.php");

    require_once("cms/project/om/ProjectI18n.php");


    class BaseProjectForm extends ActionForm {

        protected $projectI18n;
        protected $day;
        protected $month;
        protected $year;
        protected $formImage;
        protected $deleteImage;

        public function __construct() {
            $this->projectI18n = new ProjectI18n();
            $this->day = null;
            $this->month = null;
            $this->year = null;
            $this->formImage = null;
            $this->deleteImage = false;
        }

        public function getProjectI18n() {
            return $this->projectI18n;
        }

        public function setProjectI18n(ProjectI18n $projectI18n) {
            $this->projectI18n = $projectI18n;
        }

        public function getDay() {
            return $this->day;
        }

        public function setDay($day) {
            $this->day = $day;
        }

        public function getMonth() {
            return $this->month;
        }

        public function setMonth($month) {
            $this->month = $month;
        }

        public function getYear() {
            return $this->year;
        }

        public function setYear($year) {
            $this->year = $year;
        }

        public function getFormImage() {
            return $this->formImage;
        }

        public function setFormImage($formImage) {
            $this->formImage = $formImage;
        }

        public function getDeleteImage() {
            return $this->deleteImage;
        }

        public function setDeleteImage($deleteImage) {
            $this->deleteImage = $deleteImage;
        }

        public function validate() {

            $errors = new ActionMessages();

            if(is_null($this->getProjectI18n()->getName()) || strlen($this->getProjectI18n()->getName()) == 0)
                $errors->add("projectI18n->name",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.name", true)));


            if(!is_null($this->getProjectI18n()->getName()) && strlen($this->getProjectI18n()->getName()) > 0 && strlen($this->getProjectI18n()->getName()) > 255)
                $errors->add("projectI18n->name",
                    new ActionMessage("errors.maxlength", true, array(
                        new ActionMessage("prompt.name", true),
                        new ActionMessage("255", false))));


            if(is_null($this->getProjectI18n()->getIntro()) || strlen($this->getProjectI18n()->getIntro()) == 0)
                $errors->add("projectI18n->intro",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.intro", true)));


            if(is_null($this->getProjectI18n()->getDescription()) || strlen($this->getProjectI18n()->getDescription()) == 0)
                $errors->add("projectI18n->description",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.description", true)));


            if(!is_null($this->getProjectI18n()->getProject()->getUrl()) && strlen($this->getProjectI18n()->getProject()->getUrl()) > 0 && strlen($this->getProjectI18n()->getProject()->getUrl()) > 255)
                $errors->add("projectI18n->project->url",
                    new ActionMessage("errors.maxlength", true, array(
                        new ActionMessage("prompt.url", true),
                        new ActionMessage("255", false))));


            if(!is_null($this->getProjectI18n()->getProject()->getUrl()) && strlen($this->getProjectI18n()->getProject()->getUrl()) > 0 && !preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $this->getProjectI18n()->getProject()->getUrl()))
                $errors->add("projectI18n->project->url",
                    new ActionMessage("errors.url", true, new ActionMessage("prompt.url", true)));


            global $ALLOWABLE_IMAGES;
            if(!is_null($this->getFormImage()) && isset($this->formImage["size"]) && $this->formImage["size"] > 0 && !array_key_exists($this->formImage["type"], $ALLOWABLE_IMAGES))
                $errors->add("formImage",
                    new ActionMessage("errors.image", true, new ActionMessage("prompt.image", true)));

            return $errors;
        }

    }
?>